package com.ruoyi.lvlian.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.PhoneNumberValidator;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.lvlian.vo.BusinessUserInfoVo;
import com.ruoyi.system.api.domain.SysDictData;
import com.ruoyi.system.api.model.SysDeptVo;
import org.springframework.stereotype.Service;
import com.ruoyi.lvlian.mapper.BusinessUserInfoMapper;
import com.ruoyi.lvlian.service.IBusinessUserInfoService;

@Service
public class BusinessUserInfoServiceImpl implements IBusinessUserInfoService {
    private final BusinessUserInfoMapper businessUserInfoMapper;

    public BusinessUserInfoServiceImpl(BusinessUserInfoMapper businessUserInfoMapper) {
        this.businessUserInfoMapper = businessUserInfoMapper;
    }






    @Override
    public BusinessUserInfoVo getBusinessUserByPhone(String phone) {
        BusinessUserInfoVo vo = businessUserInfoMapper.getBusinessUserByPhone(phone);
        List<SysDeptVo> deptvolist = businessUserInfoMapper.queryDeptListByUserId(vo.getUserId());
        vo.setDeptList(deptvolist );
        String nickName = vo.getNickName();
        if(PhoneNumberValidator.isValidPhoneNumber(nickName  )){
            vo.setNickName( "用户"+  phone.substring(   phone.length() -4, phone.length())  );
        }

        if(StringUtils.isEmpty( vo.getName() )){
//            nickname 是真实 实名
            vo.setName( vo.getNickName() );
        }

        return  vo;
    }

    @Override
    public    List<SysDeptVo> queryDeptListByUserPhone(String phone) {
        List<SysDeptVo>  vo = businessUserInfoMapper.queryDeptListByUserPhone(phone);
        return  vo;
    }

    @Override
    public List<SysDictData> queryDictlist(SysDictData dictData) {
        return  businessUserInfoMapper.queryDictlist(dictData); // selectDictDataList
    }

    @Override
    public int updateDeptIdForUser(Long userId, Long deptId) {
        return  businessUserInfoMapper.updateDeptIdForUser(userId ,deptId );
    }
}
